<template>
    <div>   
    <el-dialog
        title="增加图书类型"
        v-model="dialogFormVisible"
        :before-close="clear"
        width=30%
        >  
        <el-form :model="form" :rules="rules" style="text-align:left" ref="form" >
        <el-form-item label="类型名" :label-width="formLabelWidth" prop="BookType">
            <el-input type="text" name="BookType" v-model="form.bookType" autocomplete="off" placeholder="请输入类型名" ></el-input>
        </el-form-item>
        </el-form>
        
        <div slot="footer" class="dialog-footer" align="right">
          <el-button @click="dialogFormVisible = false">取 消</el-button>       
          <el-button type="primary" @click="onSubmit()">确 定</el-button>
        </div>         
      </el-dialog>     
    </div>
  </template>
  <script>
  export default {
      name: 'AddBookType',
      components:{},
      data () {
        return {
          dialogFormVisible: false,        
          form: {                             
            bookType:'',           
          },
          formLabelWidth: '80px',
        }
      },
      methods: {
        clear () {       
          this.form = {            
            bookType:'',                             
          }
        },      
        onSubmit () {        
            if(this.form.bookType.trim() !== '')
            {   
              //alert("用户账号:"+ this.form.username ) 
              this.$confirm('此操作将增加图书类型: '+ this.form.bookType +' , 是否继续?', '提示', 
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                })
                .then(() => {
                    this.$message({
                        type: 'success',
                        message: '确认增加图书类型!'
                    });
                    var _this = this                 
                    let data = {
                        bookType: this.form.bookType,
                    }                    
                    this.$api.post('bookType/addBookType', data)
                        .then((res) => {                        
                            if (res.code === 200) {
                                this.$emit("onReload")
                                this.dialogFormVisible = false
                            } else {
                                this.$message({
                                    type: 'info',
                                    message: '增加图书类型失败'
                                });   
                            }        
                        })
                })                               
            }
        }
    },    
}
</script>
  
  <style scoped>
    .el-icon-circle-plus-outline {
      margin: 50px 0 0 20px;
      font-size: 100px;
      float: left;
      cursor: pointer;
    } 
  </style>